package com.example.zk2.indexfg

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.GoodsEntity
import com.example.base.entity.IndexEntity
import com.example.base.mvvm.BaseModel
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class TjViewModel:BaseViewModel() {
    //返回值
    val indexSuccess = MutableLiveData<BaseModel<IndexEntity>>()
    val indexFail = MutableLiveData<String>()

    fun index(){
        viewModelScope.launch {
            try {
                indexSuccess.value = apiServer.index()
            }catch (e:Exception){
                indexFail.value = e.message
            }
        }
    }
    //返回值--商品列表
    val goodsSuccess = MutableLiveData<BaseModel<GoodsEntity>>()
    val goodsFail = MutableLiveData<String>()
    fun indexGoods(type:Int,limit:Int,page:Int){
        viewModelScope.launch {
            try {
                goodsSuccess.value = apiServer.indexGoods(type, limit, page)
            }catch (e:Exception){
                goodsFail.value = e.message
            }
        }
    }
}